package cc.booku.owlbox.UserSettingsPage;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import cc.booku.owlbox.R;


public class HomeDirectory_A extends BaseAdapter implements ListAdapter {


    private ArrayList<HomeDirectory_C> homeDirectory_cArrayList;
    private int id;
    private Context context;
    private LayoutInflater inflater;

    public HomeDirectory_A(int sub_item, Context context, ArrayList<HomeDirectory_C> homeDirectory_cArrayList) {
        this.homeDirectory_cArrayList = homeDirectory_cArrayList;
        this.context = context;
        this.id = sub_item;
        inflater = LayoutInflater.from(context);

    }


    @Override
    public int getCount() {
        return homeDirectory_cArrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return homeDirectory_cArrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("WrongConstant")
    @Override

    public View getView(int i, View view, ViewGroup viewGroup) {

        TextView fileName = null;


        HomeDirectory_A.ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(id, null);
            fileName = (TextView) view.findViewById(R.id.filename);


            view.setTag(new ViewHolder(fileName));
        } else {
            HomeDirectory_A.ViewHolder viewHolder1 = (HomeDirectory_A.ViewHolder) view.getTag(); // 重新获取ViewHolder
            fileName = viewHolder1.fileName;


        }
        HomeDirectory_C homeDirectory_c = (HomeDirectory_C) homeDirectory_cArrayList.get(i); // 获取当前项的实例

        fileName.setText(homeDirectory_c.getFireName().toString());//对象为空
        if (homeDirectory_c.getFireName().toString().equals("不显示")) {

            fileName.setTextColor(Color.parseColor("#f29c9f"));
        }

        return view;

    }

    private final class ViewHolder {
        TextView fileName = null;

        public ViewHolder(TextView fileName) {
            this.fileName = fileName;

        }

    }

}

